<template>
  <el-container>
    <el-header style="text-align: left; font-size: 24px">
      <a href="javascript:void(0)" @click="outlogin" style="text-decoration:none;color:pink">退出登录</a>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <div class="controllerMen" @click="collfn()">|||</div>
        <el-row class="tac">
            <el-menu
              background-color="#aaa"
              text-color="#333"
              active-text-color="#ffd04b"
              :unique-opened="true"
              :collapse-transition="false"
              router
              :collapse="showMenu"
              :default-active="$route.path"
              :default-openeds="['1']"
            >
              <el-submenu :index="item.order+''" v-for="item in menulist" :key="item.id">
                <template slot="title">
                  <i :class="classobj[item.id]"></i>
                  <span>{{item.authName}}</span>
                </template>
                <el-menu-item :index="'/home/'+menuitem.path" v-for="menuitem in item.children" :key="menuitem.id">
                  <template slot="title">
                    <i class="el-icon-user"></i>
                    <span>{{menuitem.authName}}</span>
                  </template>
                </el-menu-item>
              </el-submenu>
            </el-menu>
        </el-row>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
    <el-footer>Footer</el-footer>
  </el-container>
</template>
<script>
export default {
  name: "home",
  data(){
    return{
      menulist:[],
      classobj:{
        "125":"iconfont icon-user",
        "103":"iconfont icon-3702mima",
        "101":"iconfont icon-shangpin",
        "102":"iconfont icon-danju",
        "145":"iconfont icon-baobiao",
      },
        showMenu:false
    }
  },
  methods: {
    outlogin() {
      window.sessionStorage.clear();
      this.$router.replace("/login");
    },
    async getmenus(){
      let rst=await this.$http.get("menus");
      console.log(rst);
      if(rst.meta.status!=200){
        this.$message.error("数据获取失败");
      }
      else{
        this.menulist=rst.data;
      }
    },
    collfn(){
      this.showMenu=!this.showMenu;
    }
  },
  mounted(){
    this.getmenus();
  }
};
</script>

<style scoped>
.con-home {
  height: 100%;
}
.el-header {
  background-color: #bbb;
}
.el-aside {
  background-color: #aaa;
}
.el-main {
  background-color: #eaedf1;
}
.controllerMen{
  width: 100%;
  height: 35px;
  background-color: #485164;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  letter-spacing: 0.2em;
}
</style>